package com.bw.android.bwgao6week2a.vm;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.view.View;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.io.File;

/**
 * Author: conghao
 * Date: 2023/9/19 16:53
 * Description: 用于PrepareLiveFragment
 */
public class PrepareLiveViewModel extends ViewModel {
    public MutableLiveData<Integer> liveType = new MutableLiveData<>(101);
    public MutableLiveData<String> longitude = new MutableLiveData<>("0.00");
    public MutableLiveData<String> latitude = new MutableLiveData<>("0.00");
    public MutableLiveData<String> liveTitle = new MutableLiveData<>("");
    public MutableLiveData<File> liveCoverFile = new MutableLiveData<>();

    public MutableLiveData<String> network = new MutableLiveData<>("检查网络状态");
    public void onClickCheckNetwork(View view) {
        ConnectivityManager connectivityManager = (ConnectivityManager)view.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null) {
            network.setValue("当前网络："+networkInfo.getTypeName());
        } else {
            network.setValue("无网络");
        }
    }
}
